<template>
  <view class="ikz-bid">
    <ikz-loading :css-data="loading_css"></ikz-loading>
    <view class="ikz-top-bg">
      <image class="ikz-top-bg-img" :src="service_img"></image>
    </view>
    <!-- ad -->
    <!-- list -->
    <view>
      <ikz-glist
        :show-type="type_list"
        :show-data="show_info"
        :more-status="load_more"
        @returnId="returnId"
        :receiver="isReceiver"
        :type-index="receive_status"
        @loadMore="loadMore"
      ></ikz-glist>
    </view>
    <!-- list -->
  </view>
</template>

<script>
import ikzLoading from "@/pages/Component/Public/Loading/loading.vue";
import ikzGlist from "@/pages/Component/Module/Receiver/Public/order/index/index.vue";
var app = getApp();
import ikz from "@/pages/Common/tools.js";
export default {
  components: {
    ikzLoading,
    ikzGlist,
  },
  data() {
    return {
      show_info: {
        list: [],
      },
      type_list: {
        list: [
          {
            id: 1,
            server_name: "可抢单",
          },
          {
            id: 2,
            server_name: "进行中",
          },
          {
            id: 3,
            server_name: "已完成",
          },
          {
            id: 4,
            server_name: "已取消",
          },
        ],
      },
      loading_css: {
        display: "flex",
      },
      service_img: app.globalData.service_img,
      page: 1,
      limit: 10,
      load_more: 5,
      receive_status: "",
      show_status: 2,
      // 是否为抢单员
      isReceiver: 0,
    };
  },
  created() {},
  onLoad(options) {
    this.receive_status = options.status || 1;
    this.listInfo((res) => {
      this.loading_css.display = "none";
    });
  },
  onPullDownRefresh() {
    this.page = 1;
    this.listInfo((res) => {
      uni.stopPullDownRefresh();
    });
  },
  onReachBottom() {
    if (this.load_more == 2) {
      this.page++;
      this.load_more = 3;
      this.listInfo((res) => {});
    }
  },
  onShow() {
    this.handleReceiver();
    if (this.show_status == 2) {
      this.show_status = 3;
    } else {
      this.page = 1;
      this.listInfo((res) => {});
    }
  },
  methods: {
    // 判断是否是抢单员
    handleReceiver() {
      var path = "/xyb/user/is_receiver";
      var url = app.globalData.adminPath + path;
      var data = {
        app_plat: "MP-WEIXIN",
        token: uni.getStorageSync("local_user_session"),
        agent_id: uni.getStorageSync("default_agent").id || "",
      };
      if (data.token) {
        uni.request({
          url: url,
          header: {
            "Content-Type": "application/x-www-form-urlencoded",
          },
          data: data,
          method: "POST",
          success: (res) => {
            console.log("是否为抢单员", res.data.data.is_receiver);
            uni.setStorageSync("receivers", res.data.data.is_receiver);
            this.isReceiver = res.data.data.is_receiver;
          },
          fail: function (res) {
            //调用接口失败或回传失败
            uni.showModal({
              title: "服务器繁忙",
              content: "服务器繁忙或网络不稳定，请稍后再试！",
            });
          },
        });
      }
    },
    loadMore() {
      this.page = 1;
      this.listInfo((res) => {});
    },
    returnId(e) {
      this.receive_status = e;
      this.page = 1;
      this.listInfo((res) => {});
    },
    listInfo(fn) {
      uni.showLoading({
        title: "加载中",
      });
      var path = "/xyb/user_receive/order_list";
      var data = {
        page: this.page,
        limit: this.limit,
        receive_status: this.receive_status,
      };
      ikz.post(path, data, (res) => {
        if (res.data.code) {
          var temp_list = res.data.data.data;
          if (this.page != 1) {
            for (var i = 0; i < temp_list.length; i++) {
              this.show_info.list.push(temp_list[i]);
            }
          } else {
            this.show_info.list = temp_list;
          }
          if (temp_list.length == this.limit) {
            this.load_more = 2;
          } else {
            if (this.page == 1) {
              if (temp_list.length == 0) {
                this.load_more = 5;
              } else {
                this.load_more = 4;
              }
            } else {
              this.load_more = 4;
            }
          }

      
          // console.log(this.show_info, "this.show_info");
          this.$forceUpdate();
        } else {
          uni.showModal({
            title: "提示",
            content: res.data.msg,
            showCancel: false,
            success: function (res) {},
          });
        }
        fn();
        uni.hideLoading();
      });
    },
 

    goApply() {
      var path = "/pages/Component/Module/Receiver/Program/apply/index/index";
      ikz.nav(path, "n", "");
    },
  },
};
</script>

<style scoped>
.ikz-top-bg {
  position: fixed;
  top: 0px;
  left: 0px;
}

.ikz-top-bg-img {
  width: 100%;
  height: 200rpx;
}

.ikz-banner-box {
  position: relative;
  width: 95%;
  margin: 15rpx auto 0px;
}

.ikz-location {
  box-sizing: border-box;
  position: absolute;
  top: 30rpx;
  left: 50rpx;
  display: flex;
  align-items: center;
  padding: 10rpx 40rpx 10rpx 30rpx;
  background: rgba(000, 000, 000, 0.3);
  color: #fff;
  border-radius: 70rpx;
  font-size: 25rpx;
}

.ikz-location-img {
  width: 40rpx;
  height: 40rpx;
  margin-right: 10rpx;
}

/* ad */
.ikz-ad {
  width: 95%;
  margin: 30rpx auto 0;
}

.ikz-ad-img {
  width: 100%;
  height: 150rpx;
}

/* ad */
</style>
